package com.ihrm.common.service;

import org.springframework.data.jpa.domain.Specification;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 * @author 小伟
 * @version V1.0
 * @Package com.ihrm.common.service
 * @date 2020/12/11 21:33
 * @Copyright © 2020-2021 郑州恒星科技有限责任公司
 * 提取的按照企业ID进行查询的功用service
 */
public class BaseService<T> {
    /**
     * 构造Specification封装查询条件
     * @param companyID 企业id
     * @return 查询结果
     */
    protected Specification getSpecification(String companyID) {
        Specification specification = new Specification() {
            @Override
            public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) {
                return criteriaBuilder.equal(root.get("companyId").as(String.class),companyID);
            }
        };
        return specification;
    }
}
